package databaseVersionControl.domain.ddl;

import databaseVersionControl.domain.db.DBComponent;
import databaseVersionControl.domain.dialect.Dialect;
import databaseVersionControl.domain.script.ExecutableScript;
import databaseVersionControl.infra.StringUtils;

public abstract class Composite implements ExecutableScript {

	private DBComponent component;
	private final String statement;
	
	public Composite(String statement, DBComponent component) {
		this.statement = statement;
		this.component = component;
	}

	@Override
	public String sqlInDialect(Dialect dialect) {
		String sql = statement + component.sqlInDialect(dialect);
		if (!StringUtils.lastCharacter(sql).equals(";")) sql = sql + ";";
		return sql;
	}

	@Override
	public String sqlIdentifier() {
		return statement + component.sqlIdentifier();
	}

	@Override
	public String getName() {
		return component.getName();
	}	
}